package com.example.utils;



import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

/**
 * @author Tenze
 * @description: 列表工具类
 */
public class ListUtils {

    public static final int MAX_PER_ROW = 100;

    public static <T> Stream<List<T>> slice(List<T> list){
        return slice(list,MAX_PER_ROW);
    }

    public static <T> Stream<List<T>> slice(List<T> list, int max){
        List<List<T>> buffList = new ArrayList<>();
        if(list.isEmpty()){
            return buffList.stream();
        }
        int len = list.size()/max;
        int remain = list.size()%max;
        for(int i=0;i<len;i++){
            buffList.add(list.subList(max*i,max*(i+1)));
        }
        List<T> lastList = list.subList(max * len, max * len + remain);
        if(lastList!= null && lastList.size()>0){
            buffList.add(lastList);
        }
        return buffList.stream();
    }
}
